<?php defined('IN_NWIDC') or exit('Access Invalid!');?>

<div class="wrap">
  <div class="tabmenu">
    <?php include template('layout/submenu');?>
  </div>

  
  <div>
    <link href="/shop/templates/default/css/home_point.css" rel="stylesheet" type="text/css">

    <?php
        $model_voucher = Model('voucher');
        $where = array();
        $where['voucher_t_state'] = 1;
        $where['voucher_t_end_date'] = array('gt',time());
        $voucherlist_ = $model_voucher->getVoucherTemplateList($where, '*', 0, 18);
        foreach( $voucherlist_  as $k => $v){
          if($v['voucher_t_total'] > $v['voucher_t_giveout']){
            $voucherlist [$k] = $v;
          }
        }
        $output['voucherlist'] = $voucherlist;
        // Tpl::output('voucherlist',$voucherlist);
    ?>
    <div class="ncp-main-layout">
      <?php if (!empty($output['voucherlist'])){?>
      <ul class="ncp-voucher-list">
        <?php foreach ($output['voucherlist'] as $k=>$v){?>
        <li>
          <div class="ncp-voucher">
            <div class="cut"></div>
            <div class="info"><a href="<?php echo urlShop('show_store', 'index', array('store_id'=>$v['voucher_t_store_id']));?>" class="store"><?php echo $v['voucher_t_storename'];?></a>
              <p class="store-classify"><?php echo $v['voucher_t_sc_name'];?></p>
              <div class="pic"><img src="<?php echo $v['voucher_t_customimg'];?>" onerror="this.src='<?php echo UPLOAD_SITE_URL.DS.defaultGoodsImage(240);?>'"/></div>
            </div>
            <dl class="value">
              <dt><?php echo $lang['currency'];?><em><?php echo $v['voucher_t_price'];?></em></dt>
              <dd>购物满<?php echo $v['voucher_t_limit'];?>元可用</dd>
              <dd class="time">有效期至<?php echo @date('Y-m-d',$v['voucher_t_end_date']);?></dd>
            </dl>
            <div class="point">
              <p class="required">需<em><?php echo $v['voucher_t_points'];?></em>积分</p>
              <p><em><?php echo $v['voucher_t_giveout'];?></em>人兑换</p>
            </div>
            <div class="button"><a target="_blank" href="###" nc_type="exchangebtn" data-param='{"vid":"<?php echo $v['voucher_t_id'];?>"}' class="ncp-btn ncp-btn-red">立即兑换</a></div>
          </div>
        </li>
        <?php }?>
      </ul>
      <div class="tc mt20 mb20">
        <div class="pagination"><?php echo $model_voucher->showpage()?></div>
      </div>
      <?php }else{?>
      <div class="norecord"><?php echo $lang['home_voucher_list_null'];?></div>
      <?php }?>
    </div>
  </div>


</div>

<script>
$(function(){
  //代金券兑换功能
    $("[nc_type='exchangebtn']").live('click',function(){
      var data_str = $(this).attr('data-param');
      eval( "data_str = "+data_str);
      ajaxget('index.php?act=pointvoucher&op=voucherexchange&dialog=1&vid='+data_str.vid);
      return false;
    });
});
</script>
